Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

267
Views
Formato de fecha de conversión de Javascript de "dd/mm/yy" a "mm/dd/yyyy"

¿Cómo podría convertir el formato de fecha en la entrada "fecha1" de "dd/mm/aa" a la entrada "fecha2" en el formato "mm/dd/aaaa" con Javascript o jQuery?

 <input id="date1" type="text" value="25/12/21" > <input id="date2" type="text" value="12/25/2021" >

Intenté hacer esto pero no funciona:

 var today = new Date($('#date1').val()); var dd = today.getDate(); var mm = today.getMonth()+1; var yyyy = today.getFullYear(); if(dd<10) { dd='0'+dd; } if(mm<10) { mm='0'+mm; } var converted = mm+'/'+dd+'/'+yyyy; $('#date2').val(converted);
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Puede dividir el valor por / para obtener el mes, la fecha y el año.

 var s = $('#date1').val().split('/') $('#date2').val(`${s[1]}/${s[0]}/20${s[2]}`)
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <input id="date1" type="text" value="25/12/21" > <input id="date2" type="text" value="12/25/2021" >

about 4 years ago · Juan Pablo Isaza Report

0

necesita cambiar entre mm y dd. como eso:

 var converted = dd+'/'+mm+'/'+yyyy;
about 4 years ago · Juan Pablo Isaza Report

0

Simplemente puede usar la destrucción de split y array destructing para obtener el resultado deseado

 const [dd, mm, yy] = document.querySelector("#date1").value.split('/'); document.querySelector("#date2").value = `${mm}/${dd}/20${yy}`
 <input id="date1" type="text" value="25/12/21"> <input id="date2" type="text" value="12/25/2021">

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!